package xyz.xtt.pay.client;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.common.response.ApiResult;
import xyz.xtt.pay.api.dto.GetPayStatusMapRequest;
import xyz.xtt.pay.api.dto.GetPayStatusRequest;
import xyz.xtt.pay.api.enums.PayOrderBusinessTypeEnum;
import xyz.xtt.pay.client.request.BusinessOrderRequest;
import xyz.xtt.pay.client.request.ConfirmPayOrderRequest;
import xyz.xtt.pay.client.request.FetchUnPaidOrdersRequest;
import xyz.xtt.pay.client.response.BusinessOrderDto;
import xyz.xtt.pay.client.response.BusinessOrderResponse;
import xyz.xtt.pay.client.response.PayOrderResponse;
import xyz.xtt.pay.client.response.TblPayOrderDto;

@Slf4j
@Component
public class PayClientFallbackFactory implements FallbackFactory<PayClient> {
	@Override
	public PayClient create(Throwable throwable) {
		return new PayClient() {

			@Override
			public ApiResult<List<TblPayOrderDto>> fetchUnPaidOrders(FetchUnPaidOrdersRequest fetchRequest) {
				log.info("fetchUnPaidOrders FallbackFactory param: {}", JSONUtil.toJsonStr(fetchRequest));
				return ApiResult.failure();
			}

			@Override
			public ApiResult<Boolean> confirmPayStatus(ConfirmPayOrderRequest confirmRequest) {
				log.info("confirmPayStatus FallbackFactory param: {}", JSONUtil.toJsonStr(confirmRequest));
				return ApiResult.failure();
			}

			@Override
			public ApiResult<Integer> getPayStatus(GetPayStatusRequest request) {
				log.info("getPayStatus FallbackFactory param: {}", JSONUtil.toJsonStr(request));
				return ApiResult.failure();
			}

			@Override
			public ApiResult<Map<Long, Integer>> getPayStatusMap(GetPayStatusMapRequest request) {
				log.info("getPayStatusMap FallbackFactory param: {}", JSONUtil.toJsonStr(request));
				return ApiResult.failure();
			}

			@Override
			public ApiResult<TblPayOrderDto> fetchPayOrder(Long payOrderId) {
				log.info("fetchPayOrder FallbackFactory param: {}", payOrderId);
				return ApiResult.failure();
			}

//			@Override
//			public ApiResult<List<TblAssetCardDto>> getUserCardInfo(CardInfoRequest cardInfoRequest) {
//				log.info("fetchPayOrder getUserCardInfo param: {}", cardInfoRequest);
//				return ApiResult.failure();
//			}

			@Override
			public ApiResult<List<BusinessOrderDto>> selectListByGoodsIds(BusinessOrderRequest businessOrderRequest) {
				log.info("fetchPayOrder selectListByGoodsIds param: {}", businessOrderRequest);
				return ApiResult.failure();
			}

			@Override
			public ApiResult<Map<Long, BusinessOrderDto>> getBusinessListByIds(Set<Long> ids) {
				log.info("fetchPayOrder getBusinessListByIds param: {}", ids);
				return ApiResult.failure();
			}

//			@Override
//			public ApiResult<List<TblUserFundRecordDto>> getNeedSettleRecords(Integer maxCount, Long lastId) {
//				log.info("getNeedSettleRecords FallbackFactory param: {},{}", maxCount, lastId);
//				return ApiResult.failure();
//			}
//
//			@Override
//			public ApiResult<Boolean> updateFundSettled(UpdateFundSettledRequest request) {
//				log.info("updateFundSettled FallbackFactory param: {}", JSONUtil.toJsonStr(request));
//				return ApiResult.failure();
//			}

			@Override
			public ApiResult<Boolean> mintAfterUpdateResult(Long payOrderId, Long transactionOrderId) {
				log.info("mintAfterUpdateResult FallbackFactory payOrderId: {},transactionOrderId:{}", payOrderId, transactionOrderId);
				return ApiResult.failure();
			}

			@Override
			public ApiResult<PayOrderResponse> queryPayStatus(Long businessRefId, Integer businessType) {
				log.info("mintAfterUpdateResult FallbackFactory businessRefId: {},businessType:{}", businessRefId, businessType);
				return ApiResult.failure();
			}

			@Override
			public ApiResult<BusinessOrderResponse> businessOrderInfoWithId(Long businessOrderId) {
				log.info("businessOrderInfoWithId FallbackFactory businessOrderId: {}", businessOrderId);
				return ApiResult.failure();
			}

			@Override
			public ApiResult<Boolean> skipRealPay() {
				log.info("skipRealPay FallbackFactory");
				return ApiResult.failure();
			}

			@Override
			public ApiResult<PayOrderResponse> infoPayOrderWithBusinessRefId(String businessRefId, PayOrderBusinessTypeEnum businessType) {
				log.info("infoPayOrderWithBusinessRefId FallbackFactory businessRefId:{},businessType:{}", businessRefId, businessType);
				return ApiResult.failure();
			}

		};
	}
}
